<?php


class Ajax extends CI_Controller {
	
	public function submitChat(){
		$this->load->library('chat');
		$response = $this->chat->submitChat($_POST['chatText'],$_POST['id_patient'],$_POST['id_nutritionist'],$_POST['isQuestion']);
		echo json_encode($response);
		
	}
	
	public function getChats(){
		$this->load->library('chat');
		$response = $this->chat->getChats($_GET['lastID'],$_GET['id_patient'],$_GET['id_nutritionist']);
		echo json_encode($response);
	}
	
	public function new_patient(){
		$this->load->model('Nutritionist','n');
		$this->n->logged();
		
		$this->load->model('Patient','p');
		echo $this->p->new_patient();
	}
	
	public function upload_patient(){
		$this->load->model('Nutritionist','n');
		$this->n->logged();
		
		$this->load->model('Patient','p');
		echo $this->p->upload_patient();
	}
	
	public function remove_patient(){
		$this->load->model('Nutritionist','n');
		$this->n->logged();
		
		$this->load->model('Patient','p');
		$this->p->remove_patient();
	}
	
	public function new_diet(){
		$this->load->model('Nutritionist','n');
		$this->n->logged();
		
		$this->load->model('Diet','d');
		echo $this->d->new_diet();
	}
	
	public function check_food(){
		$this->load->model('Patient','p');
		$this->p->logged();
		
		$this->load->model('Diet_check','dc');
		$this->dc->check_food();
	}
	
	public function uncheck_food(){
		$this->load->model('Patient','p');
		$this->p->logged();
		
		$this->load->model('Diet_check','dc');
		$this->dc->uncheck_food();
	}
	
	public function new_food(){	
		$this->load->model('Food','f');
		echo $this->f->new_food();
	}
	
	public function upload_food(){
		$this->load->model('Nutritionist','n');
		$this->n->logged();
		
		$this->load->model('Food','f');
		echo $this->f->upload_food();
	}
	
	public function remove_food(){
		$this->load->model('Nutritionist','n');
		$this->n->logged();
		
		$this->load->model('Food','f');
		$this->f->remove_food();
	}
	
	public function get_food(){	
		$id_food = $this->input->post('id_food');
		$this->load->model('Food','f');
		$food	 = $this->f->get_food_measure_by_id($id_food);
		echo json_encode($food);
	}
	
	public function get_measure_by_food_id(){
		$this->load->model('Measure','m');
		$this->load->model('Food','f');
		
		$id_food = $this->input->post('id_food');
		
		$food	 = $this->f->get_food($id_food);
		$measure = $this->m->get_measure($food['id_measure']);
		echo ($measure['m_name_b']);
	}
	
	public function insert_new_diet_check() {
		$this->load->model('Patient','p');
		$this->p->logged();
		
		$id_food = (int) $this->input->post('id_food');
		if($id_food==0){ // novo food
			$this->load->model('Food','f');
			$id_food = $this->f->new_food_by_patient();
		}
		
		$this->load->model('Food_element','fe');
		$id_food_el = $this->fe->new_food_element($id_food,true);
		$id_diet	= (int) $this->input->post('id_diet');

		$this->load->model('Diet_check','dc');
		$id_food_check = $this->dc->new_diet_check($id_food_el,$id_diet);
		
		echo $id_food_check;
	}
	
}

/* End of file ajax.php */
/* Location: ./nutri/application/controllers/ajax.php */